<template>
  <div>
    <!-- 面包导航 -->
    <el-breadcrumb separator="/" style="padding-left:10px;padding-bottom:10px;font-size:12px;">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>物资管理</el-breadcrumb-item>
      <el-breadcrumb-item>物资入库</el-breadcrumb-item>
    </el-breadcrumb>
    <span>类型</span>
    <span>单号</span>
    <el-input v-model="queryInfo.inNum" placeholder="请输入入库单查询" style="width: 30%" ></el-input>
    <el-button type="success" class="el-icon-search" @click="getProductByInNum">查询</el-button>
    <el-button type="primary" class="el-icon-plus" @click="addDialogVisible=true">入库</el-button>
    <el-table :data="InputProductList" stripe style="width: 100%">
      <el-table-column prop="inNum" label="入库单号" width="180"></el-table-column>
      <el-table-column prop="type" label="物资类型" width="180"></el-table-column>
      <el-table-column prop="productNumber" label="数量"></el-table-column>
      <el-table-column prop="phone" label="联系方式"></el-table-column>
      <el-table-column prop="status" label="状态"></el-table-column>
      <el-table-column prop="operator" label="操作员"></el-table-column>
      <el-table-column prop="name" label="物资提供方"></el-table-column>
      <el-table-column fixed="right" label="操作" width="180">
        <template slot-scope="scope">
          <el-button @click="findProductByInNum(scope.row.inNum)" type="warning" size="small" class="el-icon-setting" >查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="请输入添加入库信息" :visible.sync="addDialogVisible" width="80%" >
      <el-form :model="addForm" :rules="rulesAdd" ref="ruleFormAdd" label-width="100px" class="">
        <el-form-item label="物资名称">
          <el-select v-model="addForm.pName" placeholder="请选择物资名称">
            <el-option label="N95口罩" value="N95口罩"></el-option>
            <el-option label="普通医用口罩" value="普通医用口罩"></el-option>
            <el-option label="普通温度计" value="普通温度计"></el-option>
            <el-option label="生理盐水" value="生理盐水"></el-option>
            <el-option label="东北大米" value="东北大米"></el-option>
            <el-option label="防毒面具" value="防毒面具"></el-option>
            <el-option label="霸王洗发水" value="霸王洗发水"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="具体来源" prop="address">
          <el-input v-model="addForm.address"></el-input>
        </el-form-item>
        <el-form-item label="具体地址" prop="name">
          <el-input v-model="addForm.name"></el-input>
        </el-form-item>
        <el-form-item label="捐献人" prop="contact">
          <el-input v-model="addForm.contact"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="addForm.email"></el-input>
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="addForm.phone"></el-input>
        </el-form-item>
        <el-form-item label="数量" prop="productNumber">
          <el-input v-model="addForm.productNumber"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
      <el-button @click="addDialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="addProductInPut">确 定</el-button>
  </span>
    </el-dialog>
    <el-dialog title="详细信息" :visible.sync="dialogTableVisible">
      <el-table :data="productForm">
        <el-table-column property="pName" label="名称" width="150"></el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'InStocks1',
  data () {
    return {
      dialogTableVisible: false,
      // 表单校验
      rulesAdd: {
        // name: [
        //   { required: true, message: '请输入具体地址', trigger: 'blur' },
        //   { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' }
        // ],
        // operator: [
        //   { required: true, message: '请输入操作人', trigger: 'blur' },
        //   { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' }
        // ],
        // phone: [
        //   { required: true, message: '请输入电话', trigger: 'blur' },
        //   { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' }
        // ],
        // email: [
        //   { required: true, message: '请输入邮箱', trigger: 'blur' },
        //   { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' }
        // ],
        // productNumber: [
        //   { required: true, message: '请输入数量', trigger: 'blur' },
        //   { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' }
        // ]
      },
      addForm: {
        pName: '', // 物资名称
        name: '', // 集体来源
        contact: '', // 联系人
        email: '', // 邮箱
        phone: '', // 电话
        productNumber: 0, // 数量
        address: ''
      },
      productForm: [],
      addDialogVisible: false,
      // 按单号查询后台传入的参数
      queryInfo: {
        inNum: ''
      },
      InputProductList: [],
      options: [
        { value: '选项1', label: '已入库' },
        { value: '选项2', label: '回收站' },
        { value: '选项3', label: '待审核' }]
    }
  },
  mounted () {
    this.getAllProductInput()
    this.findProductByInNum()
  },
  methods: {
    // 物资入库
    addProductInPut () {
      console.log(this.addForm)
      this.$refs.ruleFormAdd.validate(async (valid) => {
        if (valid === true) {
          const { data: res } = await this.$http.post('biz/pro', this.addForm)
          if (res.code !== 200) {
            this.$message.error(res.msg)
            return false
          }
          this.$message.success(res.msg)
          await this.getAllProductInput()
          this.addDialogVisible = false
        }
      })
    },
    // 页面加载显示所有的产品
    async getAllProductInput () {
      const { data: res } = await this.$http.get('biz/pro/getAllProductInput')
      if (res.code !== 200) {
        return this.$message.error(res.msg)
      }
      this.InputProductList = res.data
      // console.log(this.InputProductList.length + '========')
      this.InputProductList.forEach(function (item) {
        if (item.status === 0) {
          item.status = '已入库'
        }
        if (item.type === 1) {
          item.type = '捐赠'
        }
        if (item.type === 2) {
          item.type = '下拨'
        }
      }
      )
    },
    // 根据入库单查询
    async getProductByInNum () {
      const { data: res } = await this.$http.get('biz/pro/getProductByInNum', { params: this.queryInfo })
      if (res.code !== 200) {
        return this.$message.error(res.msg)
      }
      this.InputProductList = res.data
    },
    // 根据入库单号查看入库产品和数量
    async findProductByInNum (inNum) {
      this.dialogTableVisible = true
      const { data: res } = await this.$http.get('biz/pro/findProductByInNum/' + inNum)
      console.log(inNum)
      if (res.code !== 200) {
        return this.$message.error(res.msg)
      }
      this.productForm = res.data
      console.log(this.productForm)
    }

  }
}
</script>

<style scoped>

</style>
